package com.aaa.bbb.mymaintain.api;


import com.aaa.bbb.common.http.ResponseResult;
import com.aaa.bbb.mymaintain.form.IssueEmployeeUpdateForm;
import com.aaa.bbb.mymaintain.form.IssuesEmployeeForm;
import com.aaa.bbb.mymaintain.form.IssuesManagerProblemForm;
import com.aaa.bbb.mymaintain.form.getJobIdForm;
import com.aaa.bbb.mymaintain.service.IssuesEmployeeSer;
import com.aaa.bbb.mymaintain.service.IssuesMaintenanceSer;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author max
 * @since 2023-11-03
 */
@CrossOrigin
@RestController
@RequestMapping("/api/issues_maintenance")
public class IssuesMaintenanceCtl {
    @Autowired
    private IssuesMaintenanceSer ser;

    @PostMapping("/getjudge")
    public ResponseResult<PageInfo<Map<String, Object>>> getJudge(@RequestBody @Valid IssuesManagerProblemForm form) {
        PageInfo<Map<String, Object>> pager = ser.queryPagerByCond(
                form.getMaintenance_id(),
                "待检查",
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

    @PostMapping("/getfund")
    public ResponseResult<PageInfo<Map<String, Object>>> getFund(@RequestBody @Valid IssuesManagerProblemForm form) {

        PageInfo<Map<String, Object>> pager = ser.queryPagerByCond(
                form.getMaintenance_id(),
                "待申请经费,经费申请中,经费申请未通过,维修不合格",
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

    @PostMapping("/getcompleted")
    public ResponseResult<PageInfo<Map<String, Object>>> getCompleted(@RequestBody @Valid IssuesManagerProblemForm form) {

        PageInfo<Map<String, Object>> pager = ser.queryPagerByCond(
                form.getMaintenance_id(),
                "待维修",
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

    @PostMapping("/applyfund")
    public void applyFund(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
        ser.updateApplyFund(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/completed")
    public void completed(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
        ser.updateApplyFund(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/canrepair")
    public void canRepair(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
        ser.updateCannotRepair(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/cannotrepair")
    public void cannotRepair(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
        ser.updateCannotRepair(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/getjobid")
    public String getJobId(@RequestBody @Valid getJobIdForm form) {
        return ser.getJobId1(form.getUsername());
    }
}

